<?php
function linechart($maxScale = NULL,$ydata = array(),$xdata = array(),$title='Line Chart',$xTitle='',$yTitle='')
{
    require_once("jpgraph/jpgraph.php");
    require_once("jpgraph/jpgraph_line.php"); 
    require_once('jpgraph/jpgraph_scatter.php');
    
    // Create the graph. These two calls are always required
    $graph = new Graph(1200,300,"auto");
    $graph->SetScale("intlin", 0, ($maxScale+3));
    
    // Setup title
    $graph->title->Set($title);
    
    $graph->SetBox(false);
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);
    $graph->yaxis->HideZeroLabel();
    
    $graph->xaxis->HideLine(false);
    $graph->xaxis->HideTicks(false,false);
    $graph->xaxis->HideZeroLabel();
    
    // make shadow image
    $graph->SetShadow();
    
    // set margin
    $graph->SetMargin(65,50,20,50);
    
    // Create the linear plot
    $lineplot=new LinePlot($ydata);
    // Add the plot to the graph
    $graph->Add($lineplot);
    
    $lineplot->SetColor("blue");
    $lineplot->value->Show();
    
    // menampilkan smt dan tahun pada sumbu X
    $graph->xaxis-> SetTickLabels($xdata);
    $graph->xaxis->SetLabelAngle(25);
    
    
    // give label for x axis
//    $graph->xaxis->SetTitle($xTitle,"center");
//    $graph->xaxis->title->Set($xTitle);

    // give label for y axis
    $graph->yaxis->title->Set($yTitle);
    
    $lineplot->mark->SetType(MARK_FILLEDCIRCLE);    
    
    return $graph; // does PHP5 return a reference automatically?
}
function multilinechart($adik_asuh = array(),$kelas = array(),$nilai = array()){
    require_once ('jpgraph/jpgraph.php');
    require_once ('jpgraph/jpgraph_line.php');

    // Setup the graph
    $graph = new Graph(1200,400,"auto");
    $graph->SetScale("intlin",0,100);

    $theme_class=new UniversalTheme;

    $graph->SetTheme($theme_class);
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Grafik Perkembangan Pendidikan Adik Asuh');
    $graph->SetBox(false);

    $graph->img->SetAntiAliasing();

    $graph->yaxis->HideZeroLabel();
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);

    $graph->xgrid->Show();
    $graph->xgrid->SetLineStyle("solid");
    $graph->xaxis->SetTickLabels($kelas);
    $graph->xgrid->SetColor('#E3E3E3');
    // give label for x axis
    $graph->xaxis->title->Set('Kelas');
    // give label for y axis
    $graph->yaxis->title->Set('Nilai');
    
    $no = 0;
    foreach ($adik_asuh as $row){
        $num = 0;
        foreach ($kelas as $rows){
            if($nilai[$no][$num][0]['pembilang'] == NULL){
                $value[$no][] = 0;
            }else{
                $value[$no][] = $nilai[$no][$num][0]['pembilang']/$nilai[$no][$num][0]['penyebut'];
            }
            $num++;
        }
        $p = new LinePlot($value[$no]);
        $graph->Add($p);
        $p->SetColor(array(rand(0, 255),  rand(0, 255),  rand(0, 255)));
        $p->SetLegend($row);
        $no++;
    }
    $graph->legend->SetFrameWeight(1);
    
    return $graph;
}
?>
